package processingdata.meteor;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class MeteorMerger {
	
	public static void main(String args[]) throws IOException
	{
		ArrayList<String> files=new ArrayList<String>();
		getFilesInDirectory("project3cs424/meteor_final", files);
		
		BufferedWriter outputWriter=new BufferedWriter(new FileWriter(new File("data/meteor.data")));
		for(int i=0;i<files.size();i++)
		{
			BufferedReader inputReader=new BufferedReader(new FileReader(new File(files.get(i))));
			while(inputReader.ready())
			{
				outputWriter.write(inputReader.readLine()+"\n");
			}
		}
		outputWriter.close();
		
	}
	
	
	public static void getFilesInDirectory(String dirName,
			ArrayList<String> files) {
		File dir = new File(dirName);

		// System.out.println(dir);
		if (dir.isDirectory()) {
			if (dir.getName().contains(".svn")) {
				// do nothing
			} else {

				File[] fileArray = dir.listFiles();

				for (int i = 0; i < fileArray.length; i++) {
					// System.out.println(fileArray[i]);
					getFilesInDirectory(fileArray[i].getAbsolutePath(), files);
				}

			}
		} else if (dir.isFile()) {
			files.add(dir.getAbsolutePath());
		}

	}

}
